package com.itheima.array;

import java.util.Scanner;

/**
 * @author jiangxun
 * @date 11-14-2024
 */
public class StudentPerformance {
    public static void main(String[] args) {
        // 定义一个数组来存储8名学习的Java成绩
        double[] scores=new double[8];
        // Scanner输入成绩
        Scanner scanner=new Scanner(System.in);
        // 提升输入成绩
        System.out.println("请输入8名学生的成绩：");
        // 循环读取8名学生的成绩
        for(int i=0;i<8;i++){
            scores[i]=scanner.nextDouble();
        }
        double average=calculateAverage(scores);
        double maxScore=findMaxScore(scores);
        double minScore=findMinScore(scores);
        System.out.println("平均成绩："+average);
        System.out.println("最高成绩："+maxScore);
        System.out.println("最低成绩："+minScore);
        // 关闭Scanner
        scanner.close();
    }

    private static double findMinScore(double[] scores) {
        double min=scores[0];
        for(double score:scores){
            if(score<min){
                min=score;
            }
        }
        return min;
    }

    private static double findMaxScore(double[] scores) {
        double max=scores[0];
        for(double score:scores){
            if(score>max){
                max=score;
            }
        }
        return max;
    }

    private static double calculateAverage(double[] scores) {
        double sum=0;
        for(double score:scores){
            sum+=score;
        }
        return sum/scores.length;
    }
}
